package com.meepo.basic.schema.feed

import android.util.Log
import java.io.Serializable

data class Stat(
    var likedCount: Int = 0,
    var liked: Boolean = false,

    var dislikedCount: Int = 0,
    var disliked: Boolean = false,

    var collectedCount: Int = 0,
    var collected: Boolean = false,

    var sharedCount: Int = 0,
    var shared: Boolean = false,

    val commentCount: Int = 0,

//    private val attitudeCountMap: Map<String, Int>? = mapOf()

    var attitudeGivens: List<Boolean> = arrayListOf(false, false, false, false), // todo
    var attitudeCounts: List<Int> = arrayListOf(0, 0, 0, 0)

) : Serializable {

    fun getAttitudeTotalCount(): Int {

        var tmp = 0

        this.attitudeCounts.forEach { v -> tmp += v }

        return tmp
    }

    fun incrShareCount() {
        sharedCount += 1
        shared = true
    }

    fun decrAttitude(index: Int) {
        val newList = arrayListOf<Int>()
        newList.addAll(attitudeCounts)
        newList[index] -= 1

        if (newList[index] < 0) newList[index] = 0

        attitudeCounts = newList

        val newBoolList = arrayListOf<Boolean>()
        newBoolList.addAll(attitudeGivens)
        newBoolList[index] = false

        attitudeGivens = newBoolList
    }

    fun incrAttitude(index: Int) {

        val newList = arrayListOf<Int>()
        newList.addAll(attitudeCounts)
        newList[index] += 1

        attitudeCounts = newList

        val newBoolList = arrayListOf<Boolean>()
        newBoolList.addAll(attitudeGivens)
        newBoolList[index] = true

        attitudeGivens = newBoolList
    }

    fun getAttitudeCount(index: Int): Int {
        if (attitudeCounts.size > index) {
            return attitudeCounts[index]
        }

        return 0
    }

    fun isAttitudeGiven(index: Int): Boolean {
        if (attitudeGivens.size > index) {
            return attitudeGivens[index]
        }
        return false
    }
}